package com.chujian.system.auth.controller;

import com.alibaba.fastjson.JSON;
import com.chujian.framework.auth.Accessor;
import com.chujian.framework.auth.AccessorHolder;
import com.chujian.framework.core.base.TsDataController;
import com.chujian.framework.core.tsdata.Result;
import com.chujian.auth.vo.UserAuthInfo;
import com.chujian.system.auth.service.IAuthService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * 授权
 */
@RestController
@Slf4j
@RequestMapping("/auth")
public class AuthController extends TsDataController {

    @Autowired
    private IAuthService authService;

    /**
     * 获取用户信息
     *
     * @return
     */
    @GetMapping("/getUserInfo")
    public Result<?> getUserInfo() {
        Accessor accessor = AccessorHolder.getAccessor();
        log.info("获取用户信息:{}", JSON.toJSONString(accessor));
        UserAuthInfo userAuthInfo = authService.getUserInfo(accessor.getUserId());
        return okRs(userAuthInfo);
    }

    /**
     * 获取用户权限码 TODO
     *
     * @return
     */
    @GetMapping("/getPermCode")
    public Result<?> getPermCode() {
        log.info("获取用户权限码:{}", AccessorHolder.getAccessor());
        return okRs(Arrays.asList("1000", "3000", "5000"));
    }
}
